package com.yjz.jvm.oom;

import java.util.ArrayList;
import java.util.List;

/**
 * VM options  添加：-XX:+HeapDumpOnOutOfMemoryError  可以在程序出现oom 时候 dump heap 信息
 * <p>
 * -Xmx4g
 * -Xms4g
 * -XX:+HeapDumpOnOutOfMemoryError
 * -XX:HeapDumpPath=/Users/yuanjinzhong/Documents/java/git/Spring_Source_Code_Learning/src/main/java/com/yjz/jvm/oom/heapdump.file
 * -XX:+PrintGCDetails
 * -XX:+PrintGCDateStamps
 * -Xloggc:/Users/yuanjinzhong/Documents/java/git/Spring_Source_Code_Learning/src/main/java/com/yjz/jvm/oom/gc.log
 * -XX:+UseG1GC
 * -XX:MaxGCPauseMillis=10
 * -XX:+PrintHeapAtGC
 *
 * @author :yuanJinZhong
 * @description: 堆溢出例程
 * @date :2018/12/4-19:14
 */
public class OomTest {
    public static void main(String[] args) throws InterruptedException {
        List list = new ArrayList();
        byte[] bytes;
        int i = 0;
        while (true) {
            Thread.sleep(300);
            i++;
//            if (i < 2000) {
//                //0.8M
//                bytes = new byte[8 / 10 * 1024 * 1024];
//            } else
                if (i % 2 == 0) {
                //0.8M
                bytes = new byte[8 / 10 * 1024 * 1024];
            } else {
                //20M
                bytes = new byte[20 * 1024 * 1024];
            }
            System.out.println("*******第" + i + "次数");
           // list.add(bytes);

        }
    }
}
